package com.yc.cloud.admin.controller;

import com.yc.cloud.common.basic.api.ResponseResult;
import com.yc.cloud.common.orm.CommonPage;
import com.yc.cloud.common.basic.dto.BasePageReqDTO;
import com.yc.cloud.admin.dto.request.HwCameraSnapshotTimeslotRelationCreateReqDTO;
import com.yc.cloud.admin.dto.request.HwCameraSnapshotTimeslotRelationUpdateReqDTO;
import com.yc.cloud.admin.vo.HwCameraSnapshotTimeslotRelationVo;
import com.yc.cloud.admin.service.HwCameraSnapshotTimeslotRelationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;

/**
 * <p>
 * 抓图策略时间段关联表 前端控制器
 * </p>
 *
 * @author kinggu
 * @since 2025-10-10
 */
@RestController
@Api(tags = "抓图策略时间段关联表")
@RequestMapping("/hw-camera-snapshot-timeslot-relations")
public class HwCameraSnapshotTimeslotRelationController {

    @Resource
    private HwCameraSnapshotTimeslotRelationService hwCameraSnapshotTimeslotRelationService;

    @ApiOperation("创建抓图策略时间段关联表")
    @PostMapping
    public ResponseResult<HwCameraSnapshotTimeslotRelationVo> create(@Validated @RequestBody HwCameraSnapshotTimeslotRelationCreateReqDTO createReqDTO) {
        HwCameraSnapshotTimeslotRelationVo newVo = hwCameraSnapshotTimeslotRelationService.create(createReqDTO);
        if (newVo != null) {
            return ResponseResult.success(newVo);
        }
        return ResponseResult.failed("创建失败");
    }

    @ApiOperation("更新抓图策略时间段关联表")
    @PutMapping("/{id}")
    public ResponseResult<HwCameraSnapshotTimeslotRelationVo> update(@PathVariable("id") Long id, @Validated @RequestBody HwCameraSnapshotTimeslotRelationUpdateReqDTO updateReqDTO) {
        updateReqDTO.setId(id);
        HwCameraSnapshotTimeslotRelationVo updatedVo = hwCameraSnapshotTimeslotRelationService.update(updateReqDTO);
        if (updatedVo != null) {
            return ResponseResult.success(updatedVo);
        }
        return ResponseResult.failed("更新失败");
    }

    @ApiOperation("删除抓图策略时间段关联表")
    @DeleteMapping("/{id}")
    public ResponseResult<Boolean> delete(@PathVariable("id") Long id) {
        boolean success = hwCameraSnapshotTimeslotRelationService.delete(id);
        if (success) {
            return ResponseResult.success(true);
        }
        return ResponseResult.failed("删除失败");
    }

    @ApiOperation("获取抓图策略时间段关联表详情")
    @GetMapping("/{id}")
    public ResponseResult<HwCameraSnapshotTimeslotRelationVo> getById(@PathVariable("id") Long id) {
        return ResponseResult.success(hwCameraSnapshotTimeslotRelationService.getVOById(id));
    }

    @ApiOperation("分页查询抓图策略时间段关联表")
    @GetMapping
    public ResponseResult<CommonPage<HwCameraSnapshotTimeslotRelationVo>> list(@Validated BasePageReqDTO pageReqDTO) {
        return ResponseResult.success(hwCameraSnapshotTimeslotRelationService.list(pageReqDTO));
    }
}
 